package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class BuildConnection {
    private static String URL = "jdbc:mysql://localhost:3306/kczy?useU" +
            "nicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
    private static String DRIVER = "com.mysql.cj.jdbc.Driver";
    private static String USER = "root";
    private static String PASSWORD = "123123";

    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
        Connection conn = null;
        if(conn == null) {
            try {
                conn = DriverManager.getConnection(URL, USER, PASSWORD);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return conn;
    }
}
